//
//  CustomTableViewCell.m
//  The car
//
//  Created by 赵洋 on 14/11/19.
//  Copyright (c) 2014年 赵洋. All rights reserved.
//

#import "CustomTableViewCell.h"
#import "RecommModel.h"
#import "UIImageView+WebCache.h"
@implementation CustomTableViewCell
- (void)dealloc
{
    [_myimage release];
    [_mylabel release];
    [_timelabel release];
    [_replylabel release];
    [_model release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addObserver:self forKeyPath:@"model" options:NSKeyValueObservingOptionNew context:nil];
        self.myimage = [[UIImageView alloc] init];
        [self.contentView addSubview:_myimage];
        self.mylabel = [[UILabel alloc] init];
        [_mylabel setNumberOfLines:0];
        [_mylabel setTextAlignment:NSTextAlignmentLeft];
        [self.contentView addSubview:_mylabel];
        self.timelabel = [[UILabel alloc] init];
        [self.contentView addSubview:_timelabel];
        self.replylabel = [[UILabel alloc] init];
        [self.contentView addSubview:_replylabel];
        [_myimage release];
        [_timelabel release];
        [_replylabel release];
        [_mylabel release];
        
    }
    return self;
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"model"]) {
        [_myimage setFrame:CGRectMake(10, 10, 100, 80)];
        [self.mylabel setFrame:CGRectMake(_myimage.frame.size.width + _myimage.frame.origin.x + 10, _myimage.frame.origin.y, self.contentView.frame.size.width - _myimage.frame.size.width - _myimage.frame.origin.x - 20, 50)];
        [self.timelabel setFrame:CGRectMake(_mylabel.frame.origin.x, _myimage.frame.size.height - 10, 100, 20)];
        [self.replylabel setFrame:CGRectMake(270, _timelabel.frame.origin.y, 100, 20)];
        [self.mylabel setText:self.model.title];
        [self.timelabel setText:self.model.time];
        [self.myimage setImageWithURL:[NSURL URLWithString:self.model.smallpic]];
        NSString *str = [self.model.replycount stringValue];
        NSString *str1 = [NSString stringWithFormat:@"%@评论", str];
        [self.replylabel setText:str1];
    }
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
